﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Masters/WithoutPermBasic.Master" CodeBehind="BottleDeliveryDetail.aspx.cs" Inherits="PMS.UI.CM.BottleDeliveryDetail" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript">
        $(function () {
            var rowData;
            var height = $("#divTotal").height();
            var content = parseFloat(height) - 150;
            $("#tbList").css("height", content);
            $("#addBottleDiv").dialog("close");
            loadTopForm();
        });
    </script>

    <script type="text/javascript">
        //加载头部表单
        function loadTopForm() {
            var paramID = com.get.ID;
            var action = com.get.action;

            $.ajax({
                type: "POST", dataType: "json",
                url: "/Logic/CM/BottleDeliveryAjax.aspx?method=GetDeliveryByID&id=" + paramID,
                success: function (data) {
                    var invUrl = '/Logic/BD/CompanyAddressAjax.aspx?method=GetAllCompanyAddressById&companyID=' + data.CustomerID + '&type=0';
                    var recUrl = '/Logic/BD/CompanyAddressAjax.aspx?method=GetAllCompanyAddressById&companyID=' + data.CustomerID + '&type=1';
                    $("#ReceiveAddressID").combobox({
                        url: recUrl,
                        valueField: 'value',
                        textField: 'text'
                    });
                    $("#InvoiceAddressID").combobox({
                        url: invUrl,
                        valueField: 'value',
                        textField: 'text'
                    });
                    $("#form1").form("load", data);
                }
            })

        }
    </script>

    <script type="text/javascript">
        // 加载发货细则
        $(function () {
            var action = com.get.action;
            var deliveryID = com.get.ID;
            $("#tbList").datagrid({
                url: '/Logic/CM/BottleDeliveryAjax.aspx?method=GetBottleDeliveryByID&id=' + deliveryID,
                loadMsg: '数据加载中请稍后……',
                rownumbers: true,
                striped: true,
                singleSelect: false,
                columns: [[
                    { field: 'ck', checkbox: true, width: 30 },
                    { field: 'ProductName', title: '产品名称', align: "center", width: 200 },
                    {
                        field: 'TechParams', title: '技术参数', align: "center", width: 200,
                        formatter: function (value, row, index) {
                            //鼠标放在文本处自动显示tooltip
                            return '<span title=' + value + '>' + value + '</span>';
                           
                        }
                    },
                    { field: 'QuotationVolume', title: '规格（L）', align: "center", width: 60 },
                    { field: 'OrderCount', title: '产品订货数', align: "center", width: 60 },
                     { field: 'SerialCode', title: '配气流水号', align: "center", width: 100 },
                     {
                         field: 'State', title: '气瓶状态', align: "center", width: 60,
                         formatter: function (value, row, Index) {
                             return com.getArrayText(StaticCombo.BottleState, value);
                         }
                     },
                    { field: 'BottleCode', title: '气瓶编号', align: "center", width: 100 },
                 { field: 'BottleVolume', title: '气瓶容积（L）', align: "center", width: 60 },
                  { field: 'CommissionDate', title: '投产日期', align: "center", width: 100, sortable: true },
                  { field: 'CompletedDate', title: '配气完成日期', align: "center", width: 100, sortable: true },
                  { field: 'AnalyseDate', title: '分析日期', align: "center", width: 100, sortable: true },
                  {
                      field: 'AnalyseRes', title: '分析结果', align: "center", width: 60,
                      formatter: function (value, row, index) {
                          return com.getArrayText(StaticCombo.BottleAnalyseRes, value)
                      }
                  },
                   { field: 'Note', title: '备注', align: "center", width: 60, sortable: true },
                ]],
                onLoadSuccess: function (data) {
                    //
                    //$("#tbList").datagrid("mergeGridColCells", ["ProductionDetailID", "ProductName", "BottleVolume", "OrderCount", "unit", "SinglePrice", "TotalPrice", "Note"]);
                }
            });

        })
    </script>

    <script type="text/javascript">

        //保存
        function funcSave() {
            var rows = $("#tbList").datagrid("getRows");
            if (rows.length == 0) {
                com.message("error", "请至少选择一个气瓶进行发货！");
                return;
            }
            var deliveryID = com.get.ID;
            var deliveryInfo = com.serializeObj("form1");
            com.ajax({
                url: '/Logic/CM/BottleDeliveryAjax.aspx?method=EditDelivery&id=' + deliveryID,
                data: deliveryInfo,
                success: function (data) {
                    com.message(data.state, data.msg);
                    if (data.state == "success") {
                        top.wrapper.tabClosethisRefreshByTitle("气瓶发货");
                    }

                }
            });
        }

        //追加气瓶
        function funcAddBottle() {
            loadDialogData();
            $("#addBottleDiv").dialog("open");
        }

        //加载可追加的气瓶数据
        //---必须在同一生产订单下才能追加---
        function loadDialogData() {
            var productCode = $("#ProductOrderCode").val();
            $("#tbAddBottleInfo").datagrid({
                url: '/Logic/CM/BottleDeliveryAjax.aspx?method=GetAddibleBottle&pdCode=' + productCode,
                loadMsg: '数据加载中请稍后……',
                pagination: true,
                rownumbers: true,
                idField: "ID",
                frozenColumns: [[{ field: 'ck', checkbox: true, width: 30 }, ]],
                columns: [[
                    { field: 'ProductName', title: '产品名称', align: "center", width: 200 },
                    {
                        field: 'TechParams', title: '技术参数', align: "center", width: 200,
                        formatter: function (value, row, index) {
                            //鼠标放在文本处自动显示tooltip
                            return '<span title=' + value + '>' + value + '</span>';
                            
                        }
                    },
                    { field: 'BottleVolume', title: '规格（L）', align: "center", width: 60 },
                    { field: 'OrderCount', title: '产品订货数', align: "center", width: 60 },
                     { field: 'SerialCode', title: '配气流水号', align: "center", width: 100 },
                     {
                         field: 'State', title: '气瓶状态', align: "center", width: 60,
                         formatter: function (value, row, Index) {
                             return com.getArrayText(StaticCombo.BottleState, value);
                         }
                     },
                    { field: 'BottleCode', title: '气瓶编号', align: "center", width: 100 },
                 { field: 'BottleVolume', title: '气瓶容积（L）', align: "center", width: 60 },
                  { field: 'CommissionDate', title: '投产日期', align: "center", width: 100, sortable: true },
                  { field: 'CompletedDate', title: '配气完成日期', align: "center", width: 100, sortable: true },
                  { field: 'AnalyseDate', title: '分析日期', align: "center", width: 100, sortable: true },
                  {
                      field: 'AnalyseRes', title: '分析结果', align: "center", width: 60,
                      formatter: function (value, row, index) {
                          return com.getArrayText(StaticCombo.BottleAnalyseRes, value)
                      }
                  },
                   { field: 'Note', title: '备注', align: "center", width: 60, sortable: true }
                ]],
                singleSelect: false,
                pageSize: 8,
                pageList: [8, 20, 50, 100],
                striped: true,
            });
        }

        //确定追加气瓶
        function addBottleOK() {
            var id = com.get.ID;
            var rows = $("#tbAddBottleInfo").datagrid("getSelections");
            if (rows.length > 0) {
                var rowdata = { BottleInfo: JSON.stringify(rows) };
                com.ajax({
                    url: "/Logic/CM/BottleDeliveryAjax.aspx?method=AddBottle2Delivery&id=" + id,
                    data: rowdata,
                    success: function (data) {
                        if (data.state == "success") {
                            $("#tbAddBottleInfo").datagrid("unselectAll");
                            $("#addBottleDiv").dialog("close");
                            $("#tbList").datagrid("reload");
                            com.message("information", "追加成功");
                        }
                    },
                });
            }
            else {
                com.message("information", "请选择一条数据");
            }
        }

        //取消追加气瓶
        function addBottleCancel() {
            $("#addBottleDiv").dialog("close");
        }

        //删除气瓶
        function funcDelBottle() {
            var rows = $("#tbList").datagrid("getSelections");
            if (rows.length > 0) {
                $.messager.confirm('确认对话框', '您确定删除选中的气瓶吗？', function (r) {
                    if (r) {
                        var rowdata = { BottleInfo: JSON.stringify(rows) };
                        com.ajax({
                            url: "/Logic/CM/BottleDeliveryAjax.aspx?method=DelBottleFromDelivery",
                            data: rowdata,
                            success: function (data) {
                                if (data.state == "success") {
                                    $("#tbList").datagrid("reload");
                                    $('#tbList').datagrid('clearSelections');
                                    com.message("information", "删除成功");
                                }
                            },
                        });
                    }
                });
            }
            else {
                com.message("information", "请选择一条数据");
            }
        }

        //取消发货
        function funcCancelDelivery() {
            $.messager.confirm('确认对话框', '您确定取消此次发货吗？', function (r) {
                if (r) {
                    var deliveryID = com.get.ID;
                    com.ajax({
                        url: "/Logic/CM/BottleDeliveryAjax.aspx?method=DelDelivery&id=" + deliveryID,
                        success: function (data) {
                            com.message(data.state, data.msg);
                            if (data.state == "success") {
                                top.wrapper.tabClosethisRefreshByTitle("气瓶发货");
                            }
                        }
                    });
                }
            });
        }
    </script>
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
    <a href="javascript:void(0)" id="btnSave" class="easyui-linkbutton" onclick="funcSave()"
        data-options="iconCls:'icon-save',plain:true">保存</a> &nbsp;&nbsp;
    <a href="javascript:void(0)" id="btnAddBottle" class="easyui-linkbutton" onclick="funcAddBottle()"
        data-options="iconCls:'icon-chart_bar_add',plain:true">追加气瓶</a> &nbsp;&nbsp;
    <a href="javascript:void(0)" id="btnDelBottle" class="easyui-linkbutton" onclick="funcDelBottle()"
        data-options="iconCls:'icon-remove',plain:true">删除气瓶</a> &nbsp;&nbsp;
     <a href="javascript:void(0)" id="btnCancel" class="easyui-linkbutton" onclick="funcCancelDelivery()"
         data-options="iconCls:'icon-cancel',plain:true">取消发货</a> &nbsp;&nbsp;
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="divTotal" style="height: auto; width: 100%">
        <div id="master" class="container_16" style="height: auto">
            <form id="form1">
                <div id="title" class="grid_16" style="text-align: center">
                    <h1>气瓶发货单</h1>
                </div>

                <div class="grid_2 alpha" style="text-align: right;">
                    发货单号 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="Code" name="Code" disabled="disabled" />
                </div>
                <div class="grid_2 seallbl" style="text-align: right;">
                    客户名称 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" class="easyui-combobox" id="CustomerID" name="CustomerID" data-options="valueField:'value',textField:'text',url:'/Logic/BD/CompanyAjax.aspx?method=GetAllCompanyNameList',panelHeight:'auto'" disabled="disabled" />

                </div>
                <div class="grid_2 seallbl" style="text-align: right;">
                    生产订单号 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="ProductOrderCode" name="ProductOrderCode" class="easyui-textbox" disabled="disabled" />

                </div>
                <div class="grid_2 seallbl" style="text-align: right;">
                    销售合同号 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="ContractCode" name="ContractCode" class="easyui-textbox" disabled="disabled" />
                </div>

                <div class="Clear"></div>
                <div class="grid_2 alpha lbl" style="text-align: right;">
                    送货地址 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="ReceiveAddressID" name="ReceiveAddressID" class="easyui-combobox" />
                    <%--<label id="ReceiveAddress"></label>--%>
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    收发员 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="FillPersonName" name="FillPersonName" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    送货人 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="DeliveryPerson" name="DeliveryPerson" class="easyui-textbox" />
                    <%--<label id="DeliveryPerson"></label>--%>
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    发货日期 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="DeliveryDate" name="DeliveryDate" class="easyui-datetimebox" />
                    <%--<label id="DeliveryDate"></label>--%>
                </div>
                <div class="Clear"></div>
                <div class="grid_2 alpha seallbl" style="text-align: right;">
                    收发票地址 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="InvoiceAddressID" name="InvoiceAddressID" class="easyui-combobox"  />
                </div>
                <div class="grid_2 seallbl" style="text-align: right;">
                    物流单号 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="EMSCode" name="EMSCode" class="easyui-textbox" />
                </div>
                <div class="grid_2 seallbl" style="text-align: right;">
                    车号 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="CarCode" name="CarCode" class="easyui-textbox" />
                </div>
                <div class="grid_2 seallbl" style="text-align: right;">
                    备注 :
                </div>
                <div class="grid_2 sealval" style="text-align: left;">
                    <input type="text" id="Note" name="Note" class="easyui-textbox" />
                </div>
                <div class="Clear"></div>
            </form>
        </div>
    </div>
    <div id="deliveryDetail" style="height: auto; width: 100%; margin-top:20px">
        <table id="tbList" title="发货气瓶">
        </table>
    </div>
    <div id="addBottleDiv" title="追加气瓶" class="easyui-dialog" style="width: 900px; height: 400px">
        <table id='tbAddBottleInfo' style='height: 320px; width: 880px; overflow: scroll'></table>
        <div class="dialog-bottom">
            &nbsp;
            <a href='#' class='easyui-linkbutton' data-options="iconCls:'icon-ok'" onclick="addBottleOK()">确定</a>&nbsp;&nbsp;&nbsp;
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="addBottleCancel()">取消</a>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var action = com.get.action;
            if (action == "view") {
                $("#btnSave").linkbutton("disable");
                $("#btnAddBottle").linkbutton("disable");
                $("#btnDelBottle").linkbutton("disable");
                $("#btnCancel").linkbutton("disable");
            }
        });
        
    </script>
</asp:Content>
